<template>
  <div>
    <!-- <Common processCode="1" title="步骤一.获取待办签报号"></Common> -->
    <div class="first">
      <div class="title">步骤一.获取待办签报号</div>

      <el-date-picker
        style="margin-left: 20px"
        v-model="sendTime"
        type="datetime"
        placeholder="选择日期时间"
      >
      </el-date-picker>
      <el-button
        type="warning"
        size="medium"
        icon="el-icon-video-play"
        :loading="loading"
        @click="execute"
        style="margin-left: 20px"
        >执行</el-button
      >
    </div>
    <div class="table">
      <el-table
        v-loading="loading2"
        :data="tableData"
        border
        height="640"
        style="width: 100%"
      >
        <el-table-column prop="index" label="序号" width="80">
        </el-table-column>
        <el-table-column prop="signMark" label="中标签报号" width="">
        </el-table-column>
        <el-table-column prop="releaseDate" label="发布日期" width="260">
        </el-table-column>
        <el-table-column prop="price" label="金额" width="260">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="medium"
              style="color: red"
              @click="deleteItem(scope.row)"
              >移除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { execute, getVisualSign, delVisualSign } from "@/common/api";
import { transTime, formatISODate } from "@/untils/trans";

export default {
  name: "Home",
  props: {},
  components: {},
  data() {
    return {
      loading: false,
      loading2: false,
      tableData: [],
      sendTime: "",
    };
  },
  created() {
    this.getTable();
  },
  methods: {
    execute() {
      this.loading = true;
      let params = {
        sendTime: this.sendTime ? formatISODate(this.sendTime) : "",
      };
      let url = "api/contract/supply/VisualSign";
      execute(url, params)
        .then((res) => {
          this.loading = false;
          if (res.success == 1) {
            this.$successMsg(res.message);
            this.getTable();
          } else {
            this.$errorMsg(res.message);
          }
        })
        .catch((err) => {
          this.loading = false;
          this.$errorMsg("接口异常");
        });
    },
    deleteItem(item) {
      // console.log(item, "111");
      this.$confirm("确认删除此条数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.delVisualSign(item.id);
        })
        .catch(() => {});
    },
    delVisualSign(id) {
      let param = {
        id: id,
      };
      delVisualSign(param)
        .then((res) => {
          if (res.success == 1) {
            this.$successMsg("删除成功");
            this.getTable();
          } else {
            this.$errorMsg(res.message);
          }
        })
        .catch((err) => {
          this.$errorMsg("接口异常");
        });
    },
    getTable() {
      this.loading2 = true;
      getVisualSign()
        .then((res) => {
          this.loading2 = false;
          if (res.success == 1) {
            this.tableData = res.data.rows;
            this.tableData.forEach((i, index) => {
              i.index = index + 1;
              i.releaseDate = transTime(i.releaseDate);
            });
          } else {
            this.$errorMsg(res.message);
          }
        })
        .catch((err) => {
          this.loading2 = false;
          this.$errorMsg("接口异常");
        });
    },
  },
};
</script>


<style lang="scss" scoped>
.first {
  display: flex;
  align-items: center;
  height: 50px;
  padding: 10px 20px;
  .title {
    font-size: 22px;
    font-weight: bold;
    color: #249087;
  }
}
.table {
  padding: 10px;
}
</style>
